package com.lxz.jucdemo.functional_Interface;

import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;

/**
 * @Author: 刘新智
 * @Date: 2025/10/27 11:32
 * @Description: 4大函数式接口
 * @Version: v1.0
 */
public class FunctionalInterfaceTest {
    public static void main(String[] args) {

        // 函数式接口1 Function 有入参和返回值
        Function<String,String> function = (str)->{
         return str;
        };
        System.out.println(function.apply("lxz"));

        // 函数式接口2 Predicate 有入参返回boolean
        Predicate<String> predicate = String::isEmpty;
        System.out.println(predicate.test(""));

        // 函数式接口3 Consumer 有入参无返回值 消费者
        Consumer<String> consumer = System.out::println;
        consumer.accept("lxz");

        // 函数式接口4 Supplier 无入参有返回值 供给者
        Supplier<String> supplier = ()->{return "lxz";};
        System.out.println(supplier.get());



    }
}
